# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=jwt-tool
pkgver=v2.3.0.r0.g3bc7407
pkgrel=1
epoch=1
pkgdesc='Toolkit for validating, forging and cracking JWTs (JSON Web Tokens).'
arch=('any')
groups=('blackarch' 'blackarch-cracker')
url='https://github.com/ticarpi/jwt_tool'
license=('GPL-3.0-or-later')
depends=('python' 'python-pycryptodomex' 'python-termcolor' 'python-cprint'
         'python-ratelimit' 'python-requests')
makedepends=('git')
source=("$pkgname::git+https://github.com/ticarpi/jwt_tool.git"
        "jwtconf.ini")
sha512sums=('SKIP'
            'a630e2ce2370678ca845550d8d7d62040cae8a9c87599931b26f6f0d009b14c78b57d369c88e00218cd992a1fac41826a9cce615334bd1e4e5e96c89ac7bd0ee')
backup=("usr/share/$pkgname/jwtconf.ini")

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md
  install -Dm 644 -t "$pkgdir/usr/share/licenses/$pkgname/" LICENSE
  install -Dm 644 -t "$pkgdir/usr/share/$pkgname/" ../jwtconf.ini

  rm README.md LICENSE setup.txt requirements.txt

  cp -a --no-preserve=ownership * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python jwt_tool.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

